﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes {
    import Engine.Managers.*;
    import Display.DialogUI.*;
    import Transactions.*;
    import Classes.util.*;
    import Classes.effects.*;
    import Display.*;
    import Classes.actions.*;

    public class MunicipalGiftBox extends Municipal {

        public function MunicipalGiftBox(_arg1:String){
            super(_arg1);
        }
        override public function getToolTipAction():String{
            if (this.isHarvestable()){
                return (ZLoc.t("Dialogs", "municipal_gift_box_open_tooltip"));
            };
            return (ZLoc.t("Dialogs", "municipal_gift_box_close_tooltip"));
        }
        override public function onPlayAction():void{
            var _local1:GenericDialog;
            if (false == Global.isVisiting()){
                if (this.isHarvestable()){
                    m_actionQueue.removeAllStates();
                    m_actionQueue.addActions(new ActionProgressBar(null, this, ZLoc.t("Main", "Upgrading"), Global.gameSettings.getNumber("actionBarHarvest")), new ActionFn(this, this.transformBuilding));
                } else {
                    _local1 = new GenericDialog(ZLoc.t("Dialogs", "not_enough_level_to_open"));
                    UI.displayPopup(_local1);
                };
            };
        }
        override public function sell():void{
            StatsManager.count("FTUE", "gift_box", "cttc_remove");
        }
        private function transformBuilding():void{
            if (!isUpgradePossible()){
                return;
            };
            StatsManager.count("FTUE", "gift_box", "cttc_open");
            var _local1 = "bus_bikeshop";
            var _local2:MapResource = new Business(_local1);
            _local2.setOuter(Global.world);
            _local2.setPosition(this.getPosition().x, this.getPosition().y);
            _local2.setId(this.getId());
            _local2.itemOwner = this.itemOwner;
            _local2.attach();
            _local2.setActive(true);
            _local2.startTime = m_startTime;
            _local2.rotateToDirection(this.getDirection());
            Global.world.citySim.roadManager.updateRoads(_local2);
            GameTransactionManager.addTransaction(new TTransformBuilding(this));
            this.detach();
            this.cleanUp();
        }
        override protected function updateState(_arg1:Number):Boolean{
            if (this.isHarvestable()){
                setState(STATE_GROWN);
                return (true);
            };
            removeStagePickEffect();
            return (false);
        }
        override public function isHarvestable():Boolean{
            return ((Global.player.level >= 5));
        }
        override protected function createStagePickEffect():void{
            this.createStagePickEffectHelper(StagePickEffect.PICK_UPGRADE);
        }
        protected function createStagePickEffectHelper(_arg1:String):void{
            var _local2:StagePickEffect = stagePickEffect;
            if (!_local2){
                _local2 = (MapResourceEffectFactory.createEffect(this, EffectType.STAGE_PICK) as StagePickEffect);
                _local2.setPickType(_arg1);
                _local2.float();
            } else {
                _local2.setPickType(_arg1);
                _local2.reattach();
                _local2.float();
            };
            this.stagePickEffect = _local2;
        }

    }
}//package Classes 
